﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.IO;

namespace MockupDesigner.AppItems.Documents
{
    public class Document : DependencyObject
    {

        public const string PREFIX_NAME = "* ";
        public const string NEW_FILE_DEFAULT_NAME = "new";

        public static int DocCounter = 1;

        public string DisplayName
        {
            get { return (string)GetValue(DisplayNameProperty); }
            set { SetValue(DisplayNameProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DocumentName.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DisplayNameProperty =
            DependencyProperty.Register("DisplayName", typeof(string), typeof(Document), new UIPropertyMetadata(string.Empty));



        public string DocumentName
        {
            get { return (string)GetValue(DocumentNameProperty); }
            set
            {
                SetValue(DocumentNameProperty, value);
                DisplayName = value;
            }
        }

        // Using a DependencyProperty as the backing store for DocumentName.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DocumentNameProperty =
            DependencyProperty.Register("DocumentName", typeof(string), typeof(Document), new UIPropertyMetadata(string.Empty));



        public DesignerCanvas DesignerCanvas
        {
            get { return (DesignerCanvas)GetValue(DesignerCanvasProperty); }
            set { SetValue(DesignerCanvasProperty, value); }
        }

        // Using a DependencyProperty as the backing store for DesignerCanvas.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DesignerCanvasProperty =
            DependencyProperty.Register("DesignerCanvas", typeof(DesignerCanvas), typeof(Document), new UIPropertyMetadata(null));

        public string FileName
        {
            get;
            set;
        }

        public bool Exists { get { return File.Exists(FileName); } }

        private bool isSaved;
        public bool IsSaved
        {
            get { return isSaved; }
            set
            {
                isSaved = value;
                if (!isSaved)
                {
                    DisplayName = DocumentName.Insert(0, PREFIX_NAME);
                }
                else
                {
                    if (DisplayName.StartsWith(PREFIX_NAME))
                    {
                        DisplayName = DisplayName.Remove(0, PREFIX_NAME.Length);
                    }
                }
            }
        }

    }
}
